package com.ruoyi.web.controller.warehouseManagement;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.InventoryCheck;
import com.ruoyi.system.service.IInventoryCheckService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 库存盘点 Controller
 *
 * @author ruoyi
 * @date 2025-06-01
 */
@Api(tags="库存盘点")
@RestController
@RequestMapping("/system/inventoryCheck")
public class InventoryCheckController extends BaseController
{
    @Autowired
    private IInventoryCheckService inventoryCheckService;

    /**
     * 通过仓库名称查询库存盘点列表
     */
    @ApiOperation("通过仓库名称查询库存盘点列表")
    @PreAuthorize("@ss.hasPermi('system:check:list')")
    @GetMapping("/list")
    public TableDataInfo list(@RequestParam (required = false) String warehouseName)
    {
        startPage();
        List<InventoryCheck> list = inventoryCheckService.selectInventoryCheckList(warehouseName);
        return getDataTable(list);
    }

    /**
     * 导出库存盘点列表
     */
    @ApiOperation("导出库存盘点列表")
    @PreAuthorize("@ss.hasPermi('system:check:export')")
    @Log(title = "库存盘点", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, @RequestParam (required = false) String warehouseName)
    {
        List<InventoryCheck> list = inventoryCheckService.selectInventoryCheckList(warehouseName);
        ExcelUtil<InventoryCheck> util = new ExcelUtil<InventoryCheck>(InventoryCheck.class);
        util.exportExcel(response, list, "库存盘点数据");
    }

    /**
     * 通过id获取库存盘点详细信息
     */
    @ApiOperation("通过id获取库存盘点详细信息")
    @PreAuthorize("@ss.hasPermi('system:check:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(inventoryCheckService.selectInventoryCheckById(id));
    }

    /**
     * 新增库存盘点
     */
    @ApiOperation("新增库存盘点")
    @PreAuthorize("@ss.hasPermi('system:check:add')")
    @Log(title = "库存盘点", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody InventoryCheck inventoryCheck)
    {
        return toAjax(inventoryCheckService.insertInventoryCheck(inventoryCheck));
    }

    /**
     * 修改库存盘点
     */
    @ApiOperation("修改库存盘点")
    @PreAuthorize("@ss.hasPermi('system:check:edit')")
    @Log(title = "库存盘点", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody InventoryCheck inventoryCheck)
    {
        return toAjax(inventoryCheckService.updateInventoryCheck(inventoryCheck));
    }

    /**
     * 通过id批量删除库存盘点信息
     */
    @ApiOperation("通过id批量删除库存盘点信息")
    @PreAuthorize("@ss.hasPermi('system:check:remove')")
    @Log(title = "库存盘点", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(inventoryCheckService.deleteInventoryCheckByIds(ids));
    }
}
